package in.muton.edushare.pages.user;

import in.muton.edushare.url.EntityPageParams;
import in.muton.edushare.wicket.models.CayenneList;
import in.muton.panels.paginator.EntityListing;

import org.apache.wicket.PageParameters;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.model.Model;

import com.edushare.common.constants.ApplicationConstants;
import com.edushare.common.vo.CourseInstances;

public class UserCourses extends UserBase {

	public UserCourses(PageParameters params) {
		super(params);
		CayenneList<CourseInstances> cL = getCourses(params);
		add(new EntityListing<CourseInstances>("thumbList", cL, this));
	}

	private CayenneList<CourseInstances> getCourses(PageParameters params) {
		CayenneList<CourseInstances> cL = new CayenneList<CourseInstances>(null);
		String id = params.getString("1", "active");
		WebMarkupContainer wmc1, wmc2, wmc3;
		add(wmc1 = new WebMarkupContainer("tab1"));
		wmc1.add(new BookmarkablePageLink<Void>("link", UserCourses.class,
				EntityPageParams.getParams(getModel(), "active")));

		add(wmc2 = new WebMarkupContainer("tab2"));
		wmc2.add(new BookmarkablePageLink<Void>("link", UserCourses.class,
				EntityPageParams.getParams(getModel(), "completed")));

		add(wmc3 = new WebMarkupContainer("tab3"));
		wmc3.add(new BookmarkablePageLink<Void>("link", UserCourses.class,
				EntityPageParams.getParams(getModel(), "all")));

		if (id.compareTo("active") == 0) {
			cL = ud.getActiveCourses();
			wmc1.add(new AttributeAppender("class", new Model<String>(
					"es-fbTabItemSelected"), " "));
			wmc2.add(new AttributeAppender("class", new Model<String>(
					"es-fbTabItem"), " "));
			wmc3.add(new AttributeAppender("class", new Model<String>(
					"es-fbTabItem"), " "));

		} else if (id.compareTo("completed") == 0) {
			cL = ud.getCompletedCourses();
			wmc1.add(new AttributeAppender("class", new Model<String>(
					"es-fbTabItem"), " "));

			wmc2.add(new AttributeAppender("class", new Model<String>(
					"es-fbTabItemSelected"), " "));

			wmc3.add(new AttributeAppender("class", new Model<String>(
					"es-fbTabItem"), " "));

		} else if (id.compareTo("all") == 0) {
			cL = ud.getActiveCourses();
			cL.add(ud.getCompletedCourses());

			wmc1.add(new AttributeAppender("class", new Model<String>(
					"es-fbTabItem"), " "));
			wmc2.add(new AttributeAppender("class", new Model<String>(
					"es-fbTabItem"), " "));
			wmc3.add(new AttributeAppender("class", new Model<String>(
					"es-fbTabItemSelected"), " "));
		}
		return cL;
	}

	@Override
	public String getActivePage() {
		return "UserCourses";
	}

	@Override
	public String getPageTitle() {
		return getModel().getObject().getCompleteUserName() + " | Courses | "
				+ ApplicationConstants.APPLICATION_NAME;
	}

	@Override
	public String getUserRole() {
		// TODO Auto-generated method stub
		return " : Courses";
	}

}
